package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 护理项目相关接口
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理", description = "提供护理项目的CRUD操作")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;
    /**
     * 根据页面请求参数，分页查询相关信息。
     *
     * @param pageNum     当前页码
     * @param pageSize 每页包含的项数
     * @param name     护理项目名称
     * @param status   状态参数
     * @return 返回一个包含查询结果的分页响应对象。
     */
    @GetMapping
    @ApiOperation("分页查询")
    public ResponseResult selectByPage(Integer pageNum, Integer pageSize, String name, Integer status){
        // 实现分页查询的逻辑
        return ResponseResult.success(nursingProjectService.selectByPage(pageNum, pageSize, name, status));
    }

    /**
     * 新增
     * @param project
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增护理项目", notes = "新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目DTO", required = true)
            @RequestBody NursingProjectDto project) {
        return toAjax(nursingProjectService.save(project));
    }

    @PutMapping
    @ApiOperation(value = "更新护理项目", notes = "根据ID更新护理项目")
    public ResponseResult update( @RequestBody NursingProjectDto project) {
        return toAjax( nursingProjectService.updateById(project));
    }
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目", notes = "根据ID删除护理项目")
    public ResponseResult delete(@PathVariable Long id) {
        return  toAjax(nursingProjectService.removeById(id)) ;
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取护理项目详情", notes = "根据ID获取护理项目详情")
    public ResponseResult get(@PathVariable Long id) {
        return ResponseResult.success(nursingProjectService.getById(id));
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有护理项目", notes = "根据ID获取护理项目详情")
    public ResponseResult getAll() {
        return ResponseResult.success(nursingProjectService.getAll());
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "更改护理项目状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        return toAjax(nursingProjectService.updateStatus(id, status));
    }
}
